<template>
  <div>
    <FilterTable
      ref="table"
      :isSelectColumn="false"
      :columns="columns"
      height="auto"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onColumnsChange="columns => this.columns = columns"
    >
    </FilterTable>

    <Drawer
      :visible.sync="visible2"
      :title="title"
      :width="1200"
      destroyOnClose
      :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"
    >
      <salesVisitChildrenDetail :showChildren="showChildren" :type="type" :recordVersion="recordVersion" :careTargetId="careTargetId" :employeeId="employeeId" :billId="billId" @changeHandle="changeHandle" @close="closeHandler" />
    </Drawer>

    <Drawer
      :visible.sync="visible"
      :title="title"
      :width="1200"
      destroyOnClose
      :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"
    >
      <preSalesChildrenDetail :showChildren="showChildren" :type="type" :recordVersion="recordVersion" :careTargetId="careTargetId" :employeeId="employeeId" :billId="billId" @changeHandle="changeHandle" @close="closeHandler" />
    </Drawer>

    <Drawer
      :visible.sync="visible3"
      :title="title"
      :width="1200"
      destroyOnClose
      :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"
    >
      <specialHolidayChildrenDetail :isShowHistory="isShowHistory" :selectedRows="selectedRows" @changeHandle="changeHandle" @close="closeHandler" />
    </Drawer>

    <Drawer
      :visible.sync="visible4"
      :title="title"
      :width="1200"
      destroyOnClose
      :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"
    >
      <customerBirthdayChildrenDetail :isShowHistory="isShowHistory" :selectedRows="selectedRows" @changeHandle="changeHandle" @close="closeHandler" />
    </Drawer>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { formatdate } from '@/utils/index';
import {
  queryCareTask
} from '@/api/customerCare/saleVisit/salesVisit';
import salesVisitChildrenDetail from '../saleVisit/salesVisit/salesVisitDetail';
import specialHolidayChildrenDetail from '../saleVisit/customerHoliday/specialHolidayDetail';
import customerBirthdayChildrenDetail from '../saleVisit/potentialCustomerBirthday/customerBirthdayDetail';
import preSalesChildrenDetail from '../saleVisit/preSales/preSalesDetail';

export default {
  name: 'careTask',
  mixins: [dictionary],
  components: {
    salesVisitChildrenDetail,
    specialHolidayChildrenDetail,
    customerBirthdayChildrenDetail,
    preSalesChildrenDetail
  },
  props: {
    employeeId: String,
    careTargetId: String,
    showChildren: Boolean,
    selectedRows: Array
  },
  data() {
    return {
      columns: this.createTableColumns(),
      fetchApi: queryCareTask,
      fetchParams: {employeeId:this.employeeId,careTargetId:this.careTargetId},
      handleType: '',
      title: '',
      formData: {},
      recordVersion: '',
      type: '',
      billId: '',
      visible: false,
      visible2: false,
      visible3: false,
      visible4: false,
      isShowHistory: true
    };
  },
  methods: {
    createTableColumns() {
      return [
        // {
        //   title: '操作',
        //   dataIndex: 'column-action',
        //   fixed: 'left',
        //   width: 50,
        //   render: (props, h) => {
        //     return (
        //       <div>
        //         <el-button size="mini" type="text" v-if={this.showChildren} onClick={() => this.careHandle(props.row)}>
        //           关爱
        //         </el-button>
        //       </div>
        //     );
        //   }
        // },
        {
          title: '序号',
          dataIndex: 'index',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '关爱类型',
          dataIndex: 'careTypeCode',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            return <div>{this.createDictText(props.row.careTypeCode, '1572')}</div>;
          }
        },
        {
          title: '任务编号',
          dataIndex: 'taskNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '分配日期',
          dataIndex: 'createdAt',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            if(props.row.createdAt&&props.row.createdAt!=''){
              return <div>{formatdate(new Date(parseInt(props.row.createdAt)),1)}</div>;
            }
          }
        },
        {
          title: '要求完成日期',
          dataIndex: 'requiredDate',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            if(props.row.requiredDate&&props.row.requiredDate!=''){
              return <div>{
                formatdate(new Date(parseInt(props.row.requiredDate)),1)}</div>;
            }
          }
        },
        {
          title: '关爱名称',
          dataIndex: 'careName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '关爱人员',
          dataIndex: 'employeeName',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ]
    },
    careHandle(row){
      this.type = 'add';
      this.billId = row.billId+"";
      this.employeeId = row.careEmpId+"";
      this.careTargetId = row.careTargetId+"";
      this.recordVersion = row.recordVersion+"";
      if(row.careTypeCode == 15721001){
        this.title = '售前回访关爱';
        this.visible = true;
      }else if(row.careTypeCode == 15721002){
        this.title = '销售回访关爱';
        this.visible2 = true;
      }else if(row.careTypeCode == 15721003){
        this.visible4 = true;
        this.selectedRows = [{"careTargetId":row.careTargetId}];
      }else if(row.careTypeCode == 15721005){
        this.visible3 = true;
        this.selectedRows = [{"careTargetId":row.careTargetId}];
      }
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    closeHandler(val, type) {
      this.visible = val;
      this.visible2 = val;
      this.visible3 = val;
      this.visible4 = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  }
};
</script>

<style lang="less">
</style>
